﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_TeacherClass
/// </summary>
public class DAL_TeacherClass : clsConnection
{
    DataTable dt = new DataTable();
    clsQueryList clsquery = new clsQueryList();
    public DataTable DAL_TeacherClass_getAllData()
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM TeacherClass");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_TeacherClass_addtodel(int id)
    {
        try
        {
            string sql = "delete from TeacherClass where id=" + id;
            clsquery.addSQL(sql);
        }
        catch
        {
            return false;
        }
        return true;
    }
    public Boolean DAL_TeacherClass_del()
    {
        try
        {
            clsquery.Execute();
        }
        catch
        {
            return false;
        }
        return true;
    }
    public DataTable DAL_TeacherClass_getAllById(int id)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM TeacherClass WHERE id=" + id);
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_TeacherClass_getAllByTeacherid(string tid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM TeacherClass WHERE teacherid= '" + tid + "'");
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_TeacherClass_getAllByClassid(string cid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM TeacherClass WHERE classid= '" + cid + "'");
        }
        catch
        {
        }
        return dt;
    }
    //dang ky lop
    public DataTable DAL_TeacherClass_getDK(string id)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM TeacherClass WHERE teacherid='" + id + "'");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_TeacherClass_InsertDK(DTO_TeacherClass obj)
    {
        try
        {
            string sql = "INSERT INTO TeacherClass(teacherid, classid) VALUES(@teacherid, @classid)";
            AddParameter(new SqlParameter("@teacherid", obj.Teacherid));
            //AddParameter(new SqlParameter("@classtype", obj.Classtype));
            AddParameter(new SqlParameter("@classid", obj.Classid));
            //AddParameter(new SqlParameter("@status", obj.Status));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
    public DataTable DAL_TeacherClass_getSearch(string teacherid, string classid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM TeacherClass WHERE teacherid Like '%" + teacherid + "%' AND classid LIKE N'%" + classid + "%'");
        }
        catch
        {
        }
        return dt;
    }
}